<template>
  <s-dialog :dialog="dialogReject">
    <p slot="title">驳回{{data.title}}<span>{{data.titleDetails + dialogReject.row[data.titleDetailsRow]}}</span></p>
    <s-form :form="formDialogReject" ref="formDialogReject">
      <el-row>
        <el-col :xs="24" :lg="{span: 23, offset: 0}" class="">
          <el-form-item prop="remarks" label="驳回原因">
            <el-input
              type="textarea"
              :rows="4"
              v-model="formDialogReject.remarks"
              placeholder="请填写驳回原因"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </s-form>
    <el-button slot="footer" @click="dialogRejectSave">确认驳回</el-button>
  </s-dialog>
</template>

<script>
  import {AutoVue} from '~/plugins/Tools';
  function __formDialogReject () {
    return {
      remarks: { value: '', rule: ['vNull'], cRemarks: '' },
      id: { value: '', rule: [], cRemarks: '' },
    };
  }
  export default AutoVue({
    data: {
      datas: {
        reimbursement: {
          title: '报销单',
          titleDetails: '报销合计：',
          titleDetailsRow: 'money',
          url: '/reimbursement/reject',
        },
        emplyee: {
          title: '员工',
          titleDetails: '名称：',
          titleDetailsRow: 'bxSupplierName',
          url: '/empolyee/reject',
        },
        information: {
          title: '供应商',
          titleDetails: '名称：',
          titleDetailsRow: 'bxSupplierName',
          url: '/supplier/reject',
        },
      },
      data: {},

      formDialogReject: __formDialogReject(),
      dialogReject: {
        row: {},
      },
    },
    props: {
      type: {
        type: String,
        default: 'reimbursement',
      },
    },
    methods: {
      async open (row) {
        this.dialogReject.row = row;
        this.formDialogReject.id = row.id;
        this.dialogReject.visible = true;
      },
      dialogRejectSave () {
        this.VALIDATE('formDialogReject', async option => {
          let json = await this.post(this.data.url, option);
          this.dialogReject.dialogInit.call(this);
          this.$emit('success', json);
        });
      },
    },
    mounted () {
      this.data = this.datas[this.type];
    },
  });
</script>
